package grape.attend.rest.clock.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.attend.rest.clock.form.ClockListForm;
import grape.attend.service.clock.query.ClockListQuery;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.attend.rest.clock.form.ClockCreateForm;
import grape.attend.rest.clock.form.ClockUpdateForm;
import grape.attend.rest.clock.form.ClockListPageForm;
import grape.attend.rest.clock.vo.ClockVo;
import grape.attend.rest.clock.mapper.ClockWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.attend.service.clock.po.Clock;
import grape.attend.service.clock.api.IClockService;
import java.util.List;
/**
 * <p>
 * 打卡设置 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-05-08
 */
@RestController
@RequestMapping("/attend/clock")
@Api(tags = "打卡设置相关接口")
public class ClockController extends BaseController<ClockVo, Clock> {

    @Autowired
    private ClockWebMapper currentWebMapper;
    @Autowired
    private IClockService currentService;



     @ApiOperation("添加打卡设置")
     @PreAuthorize("hasAuthority('clock:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public ClockVo create(@RequestBody @Valid ClockCreateForm cf) {
         Clock po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询打卡设置")
     @PreAuthorize("hasAuthority('clock:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public ClockVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除打卡设置")
     @PreAuthorize("hasAuthority('clock:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新打卡设置")
     @PreAuthorize("hasAuthority('clock:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public ClockVo update(@PathVariable String id,@RequestBody @Valid ClockUpdateForm uf) {
         Clock po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }
    @ApiOperation("不分页查询打卡设置")
    @PreAuthorize("hasAuthority('clock:single:list')")
    @GetMapping("/list")
    @ResponseStatus(HttpStatus.OK)
    public List<ClockVo> list(ClockListForm listForm) {
        Clock po = currentWebMapper.formToPo(listForm);
        ClockListQuery clockListQuery = new ClockListQuery();
        clockListQuery.setPoQuery(po);
        return super.list(clockListQuery);
    }
    @ApiOperation("分页查询打卡设置")
    @PreAuthorize("hasAuthority('clock:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<ClockVo> listPage(ClockListPageForm listPageForm) {
         Clock po = currentWebMapper.formToPo(listPageForm);
        ClockListQuery clockListQuery = new ClockListQuery();
        clockListQuery.setPoQuery(po);
        return super.listPage(clockListQuery,listPageForm);
     }

}
